<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="../common/taglibs.jsp" %>
<%
    response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setDateHeader("Expires", 0);
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<jsp:include page="/page/common/include.jsp"></jsp:include>
<script language="javascript" type="text/javascript">

$(document).ready(function(){
	
	/** 初始化新增Panel位置 */
	$("#addPanel").offset({
		top:30,
		left:($(window).width()-400)*0.5
	});
	
	/** 初始化新增Panel */
	$("#addPanel").panel({
		width:400,
		height:300,
		onBeforeOpen:function(){
			/** 初始化业务系统下拉列表 */
			$('#sysCode_input').combobox({
				valueField:'value',
				textField:'name',
				panelHeight:'auto',
				url:'<%=request.getContextPath()%>/systemInfo/systemInfoAction!getSysCodeComboxValue.do',
				onLoadSuccess:function(){
					clearFuncTypeInput();
					clearParentFuncCodeInput();
					$("#funcType_input").combobox("disable");
					$("#parentFuncCode_input").combobox("disable");
				},
				onChange:function(newValue,oldValue){
					if(newValue == ''){
						clearFuncTypeInput();
						$("#funcType_input").combobox("disable");
					}else{
						initFuncTypeInputData();
						$("#funcType_input").combobox("enable");
					}
				}
			});
			/** 初始化资源类型下拉列表 */
			$("#funcType_input").combobox({
				panelHeight:'auto',
				valueField:'id',
				textField:'text',
				onChange:function(newValue,oldValue){
					clearParentFuncCodeInput();
					if(newValue == ''){
						$("#parentFuncCode_input").combobox("disable");
						return;
					}
					var sysCodeInput = $('#sysCode_input').combobox('getValue');
					$.ajax({
						url : '<%=request.getContextPath()%>/functionInfo/functionInfoAction!getFuncInfoComboxValue.do',
						type : 'post',
						dataType : 'text',
						cache : false,
						data : {
							sysCode : sysCodeInput,
							funcType : newValue
						},
						success : function(data) {
							$("#parentFuncCode_input").combobox("enable");
							$("#parentFuncCode_input").combotree('loadData',eval(data));
						}
					});
				}
			});
			/** 初始化父节点下拉列表 */
			$("#parentFuncCode_input").combotree();
		}
	});
})

/**
 * 初始化资源类型下拉列表
 */
function initFuncTypeInputData(){
	$("#funcType_input").combobox("loadData",[{id:'',text:'请选择'},{id:'0',text:'模块节点'},{id:'1',text:'菜单节点'},{id:'2',text:'功能节点'}]);
	$("#funcType_input").combobox("setValue",'');
}

/**
 * 清空资源类型下拉列表
 */
function clearFuncTypeInput(){
	$("#funcType_input").combobox("loadData",[{id:'',text:'请选择'}]);
	$("#funcType_input").combobox("setValue",'');
}

/**
 * 清空父节点资源类型下拉列表
 */
function clearParentFuncCodeInput(){
	 $("#parentFuncCode_input").combotree("clear");
	 $("#parentFuncCode_input").combotree("loadData",[{id:'',text:'请选择'}]);
	 $("#parentFuncCode_input").combotree("setValue",'');
}

/**
 * 表单提交
 */
function formSubmit(){
	disableLinkButton();
	if(validateForm() == false){
		return;
	}
	var funcInfo = JSON.stringify(getFormValue());
	$.ajax({
		url : '<%=request.getContextPath()%>/functionInfo/functionInfoAction!addFunctionInfo.do',
		type : 'post',
		dataType : 'text',
		cache : false,
		data : {
			funcInfo : funcInfo
		},
		success : function(data) {
			enableLinkButton();
			var j = JSON.parse(data);
			if (j.result = 'success') {
				messageAlertInfo("操作结果","资源信息增加成功！",formClear);
			} else {
				messageAlertError("操作结果",j.msg);
			}
		}
	});
}

/**
 * 获取表单的值
 */
function getFormValue() {
	var funcInfo = {
		sysCode : $('#sysCode_input').combobox('getValue'),
		funcCode : $("#funcCode_input").val(),
		funcName : $("#funcName_input").val(),
		funcType : $('#funcType_input').combobox('getValue'),
		funcUrl : $("#funcUrl_input").val(),
		parentFuncCode : $('#parentFuncCode_input').combobox('getValue'),
		orderIndex : $("#orderIndex_input").val()
	};
	return funcInfo;
}

/**
 * 表单验证
 */
function validateForm(){
	return true;
}

/**
 * 清空表单
 */
function formClear(){
	goToPage('<%=request.getContextPath()%>/functionInfo/functionInfoAction!initAddFunctionInfo.do');
}
</script>
</head>

<body style="background: white;">
	<div id="addPanel" style="position:absolute;padding-top: 10px" align="center">
		<table>
    		<tr>
    			<td>业务系统:</td>
    			<td>
    				<input id="sysCode_input" style="width:154px;"/>
    			</td>
    		</tr>
    		<tr>
    			<td>资源编号:</td>
    			<td><input id="funcCode_input"  type="text" /></td>
    		</tr>
    		<tr>
    			<td>资源名称:</td>
    			<td>
    				<input id="funcName_input"  type="text" />
    			</td>
    		</tr>
    		<tr>
    			<td>资源类型:</td>
    			<td>
    				<input id="funcType_input" style="width:154px;"/>
    			</td>
    		</tr>
    		<tr>
    			<td>资源地址:</td>
    			<td>
    				<input id="funcUrl_input"  type="text" />
    			</td>
    		</tr>
    		<tr>
    			<td>父节点:</td>
    			<td>
					 <input id="parentFuncCode_input" style="width:154px;"/>
    			</td>
    		</tr>
    		<tr>
    			<td>排序号:</td>
    			<td>
    				<input id="orderIndex_input" type="text"/>
    			</td>
    		</tr>
    		<tr>
    			<td colspan="2" align="center" style="padding: 15px">
    				<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="formSubmit()">提交</a>
					<a class="easyui-linkbutton" data-options="iconCls:'icon-reload'" href="javascript:void(0)" onclick="formClear()">清空</a>
    			</td>
    		</tr>
    	</table>
	</div>
</body>
</html>